package com.kakaxi.mybilibili.utils;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;

/**
 * 加载对话框工具类
 * Created by kakaxi on 16/11/23.
 */

public class ProgressDialogUtil {

    /** 加载对话框 **/
    public static ProgressDialog progressDialog;

    /**
     * 显示
     *
     * @param activity 想要显示的活动
     */
    public static void show(Activity activity) {
        if (progressDialog == null) {
            showDialog(activity);
        } else if (!progressDialog.isShowing()) {
            showDialog(activity);
        }
    }

    /**
     * 真正显示
     *
     * @param activity 互动
     */
    private static void showDialog(final Activity activity) {
        progressDialog = ProgressDialog.show(activity, null, "正在加载中...", true, true, new
                DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        activity.finish();
                    }
                });
    }

    /**
     * 隐藏
     */
    public static void hide() {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
    }

}
